package club.hicode.daydayup.redis.distribute;

import cn.hutool.core.thread.ThreadUtil;
import cn.hutool.core.util.RandomUtil;
import org.junit.Test;

import java.io.IOException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

/**
 * 测试
 *
 * @author Liu Chunfu
 * @date 2018-06-11 下午5:03
 **/
public class SimpleLockTest {
    @Test
    public void testLock1() throws IOException {

        ExecutorService executorService = Executors.newCachedThreadPool();
        for (int i = 0; i < 5; i++) {
            executorService.execute(() -> {
                SimpleLock lock = new SimpleLock();
                lock.lock();
                System.out.println(Thread.currentThread().getId() + "获取锁做事。。。");
                ThreadUtil.sleep(RandomUtil.randomInt(3), TimeUnit.SECONDS);
                lock.unlock();
            });
        }

        System.in.read();
    }
}
